﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Domain.Entity;

namespace Pro260Website.Infrastructure
{
    public enum GameViewType
    {
         Games, MostPopular, TopReviewed, TopRated
    }

    public static class GameViewFactory
    {
        public static IQueryable<Game> GenerateList(this IQueryable<Game> query, GameViewType type)
        {
            if (type == GameViewType.MostPopular)
            {
                return query.OrderByDescending(g => ((( 
                    g.TotalRating / (g.NumRatings + 1)) * 10) + (g.Reviews.Count * 30)));
            }
                

            if (type == GameViewType.TopReviewed)
                return query.Where(g => g.Reviews.Count > 0).OrderByDescending(g => g.Reviews.Count);

            if (type == GameViewType.TopRated)
                return query.Where(g => g.NumRatings > 0).OrderByDescending(g => g.TotalRating/g.NumRatings);
            
            return query;
        }
    }
}